package com.servlet;

import com.service.StudentService;
import com.sun.org.apache.bcel.internal.generic.NEW;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.util.ArrayList;

@WebServlet("/ServletNew")
public class ServletNew extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);
    }
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        ArrayList<String> list = new ArrayList<>();
        StudentService studentService = new StudentService();
        String username = request.getParameter("username");
        String psw = request.getParameter("psw");
        Boolean b = studentService.newUser(username, psw);
        if (b){
            response.getWriter().write("注册成功...");
            response.setHeader("Refresh","2;URL=index.jsp");
        }else{
            response.getWriter().write("注册失败...");
            response.setHeader("Refresh","2;URL=new.jsp");
        }
    }
}
